package top.dbpanda.cmsjpa.learn.thread.juc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author 20018954
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Swimmer implements Delayed {
    private String name;
    private Long endTime;

    @Override
    public long getDelay(TimeUnit unit) {
        return endTime - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        Swimmer swimmer = (Swimmer) o;
        return this.getDelay(TimeUnit.SECONDS) - swimmer.getDelay(TimeUnit.SECONDS) > 0 ? 1 : 0;
    }
}
